package com.hospital.service.project.controller;

import com.hospital.service.project.entity.ProInfoDetails;
import com.hospital.service.project.model.param.ProInfoDetailsParam;
import com.hospital.service.project.model.param.ProInfoDetailsQueryForOneRowParam;
import com.hospital.service.project.model.param.ProInfoDetailsQueryPageParam;
import com.hospital.service.project.model.vo.ProInfoDetailsVo;
import com.hospital.service.project.service.ProInfoDetailsService;
import common.core.util.CommonUtil;
import common.core.util.Result;
import enhance.plus.logic.LogicBaseController;
import enhance.plus.util.Page;
import enhance.plus.util.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;


/**
 * 实验项目详细表 控制器
 *
 * @author xhl
 * @created 2020-10-10 14:59:20
 */
@Slf4j
@Validated
@RestController
@Api(tags = "实验项目详细表")
@RequestMapping("/project/proInfoDetails")
public class ProInfoDetailsController extends LogicBaseController<ProInfoDetailsService, ProInfoDetails> {

    @Autowired
    private ProInfoDetailsService proInfoDetailsService;

    @ApiOperation(value = "保存实验项目详细表的数据")
    @RequestMapping(value = "/save" , method = RequestMethod.PUT)
    public Result save(@Valid @RequestBody ProInfoDetailsParam param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        log.debug("开始保存实验项目详细表-->{}",param);
        return Result.success(this.proInfoDetailsService.save(CommonUtil.copyBean(param,ProInfoDetails.class)));
    }

    @ApiOperation(value = "更新实验项目详细表的数据")
    @RequestMapping(value = "/update" , method = RequestMethod.PUT)
    public Result update(@Valid @RequestBody ProInfoDetailsParam param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        log.debug("开始跟新实验项目详细表-->{}",param);
        return Result.success(this.proInfoDetailsService.updateById(CommonUtil.copyBean(param,ProInfoDetails.class)));
    }

    @ApiOperation(value = "删除实验项目详细表的一条数据")
    @RequestMapping(value = "/delete" , method = RequestMethod.DELETE)
    @ApiImplicitParams(
        @ApiImplicitParam(name= "id" ,value = "数据ID", required = true , example = "-1" )
    )
    public Result delete(@Valid @RequestParam @NotBlank(message = "删除数据ID不能为空") String id){
        log.debug("开始删除实验项目详细表的数据-->{}",id);
        return Result.success(this.proInfoDetailsService.removeById(id));
    }

    @ApiOperation(value = "根据条件查询一条实验项目详细表的数据")
    @RequestMapping(value = "/queryForOneRow" , method = RequestMethod.POST)
    public Result<ProInfoDetailsVo> queryForOneRow(@Valid @RequestBody ProInfoDetailsQueryForOneRowParam param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        ProInfoDetails row = this.proInfoDetailsService.getOne(param.convertParamToQueryWapper());
        return Result.success( CommonUtil.copyBean(row, ProInfoDetailsVo.class));
    }

    @ApiOperation(value = "根据条件分页查询实验项目详细表的数据")
    @RequestMapping(value = "/queryPage" , method = RequestMethod.POST)
    public Result<Page<ProInfoDetailsVo>> queryPage(@Valid @RequestBody ProInfoDetailsQueryPageParam param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        return Result.success(this.proInfoDetailsService.page(param.page(),param.convertParamToQueryWapper()));
    }

}
